package com.yoouce.patchmng.init;

import com.yoouce.patchmng.service.UserService;
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContextEvent;

/**
 * 系统初始化加载类，加载Spring的同时，加载用户信息，权限列表
 * Created by administrator on 15-9-28.
 */
public class SystemInit extends ContextLoaderListener {

    /**
     * 日志常量
     */
    private static final Logger logger = Logger.getLogger(ContextLoaderListener.class);

    /**
     * 重写Spring原有的配置文件
     *
     * @param event 系统上下文
     */
    public void contextInitialized(ServletContextEvent event) {
        logger.info("开始加载spring");
        super.contextInitialized(event);

        ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());

        String realPath = event.getServletContext().getRealPath("/");

        SystemContants.SYSTEM_FULL_PATH=realPath;

        logger.info("开始加载用户信息和权限信息");
        UserService userService = (UserService) context.getBean("UserService");
        userService.initUserInfo();

    }

}
